package com.ebc.eservice.controller.pc;

import com.ebc.eservice.service.EbcUserService;
import com.ebc.eservice.util.CurrentUser;
import com.ebc.eservice.util.JsonResult;
import com.ebc.eservice.util.common.constant.ApiTextHelperConstant;
import com.ebc.eservice.util.common.constant.DeveloperConstant;
import com.ebc.eservice.vo.admin.CompanyAccountVo;
import com.ebc.eservice.vo.admin.CompanyModifyReqVo;
import com.ebc.eservice.vo.admin.modifyPwdVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author: Joey
 * @Description:后端-平台管理
 * @date:2022/9/26 2:14
 */
@Api(tags = "后台管理系统-设置-平台管理")
@RestController
@RequestMapping("/system/setting")
public class AdminTemplateController {

    @Autowired
    private EbcUserService ebcUserService;
    //获取企业账号列表
    @ApiOperation(value = "获取企业账号列表", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getCompanyAccountList")
    public JsonResult getCompanyAccountList(){
        int current=1;
        int size = 50;
        return ebcUserService.getCompanyAccountList(current,size);
    }

    //添加企业账号 返回的id 用于添加照片
    @ApiOperation(value = "添加企业账号", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/addCompanyAccount")
    public JsonResult addCompanyAccount(CompanyAccountVo companyAccountVo){
        return ebcUserService.addCompanyAccount(companyAccountVo);
    }

    //添加企业信息照片
    @ApiOperation(value = "添加[修改]企业照片", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/addCompanyPic")
    public JsonResult addCompanyPic(@RequestParam(value = "file") MultipartFile file,
                                    @RequestParam(value = "companyId")Integer companyId) throws IOException {
        return ebcUserService.addCompanyPic(companyId,file);
    }

    //修改企业账户信息
    @ApiOperation(value = "更新企业账号信息", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/updateCompanyInfo")
    public JsonResult updateCompanyInfo(@RequestParam(value = "file") MultipartFile file,
                                        @RequestParam(value = "companyId")Integer companyId,
                                        @RequestParam(value = "possessorId")Integer possessorId,
                                        @RequestParam(value = "companyName")String companyName,
                                        @RequestParam(value = "shortName")String shortName,
                                        @RequestParam(value = "managerName")String managerName,
                                        @RequestParam(value = "managerPhone")String managerPhone) throws IOException {
        CompanyModifyReqVo reqVo = new CompanyModifyReqVo();
        reqVo.setCompanyId(companyId).setCompanyName(companyName).setManagerName(managerName)
                .setManagerPhone(managerPhone).setPossessorId(possessorId).setShortName(shortName).setFile(file);
        return ebcUserService.ModifyCompanyInfo(reqVo);
    }



    //停用企业账号
    @ApiOperation(value = "企业账号使用权限 [1-开启 0-关闭]", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/updateCompanyUse")
    public JsonResult updateCompanyUse(Integer companyId,Integer useStatus) throws IOException {
        return ebcUserService.UpdateUseStatus(companyId,useStatus);
    }


    @ApiOperation(value = "设置-修改账户密码", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/modifyPassword")
    public JsonResult modifyPassword(@RequestBody modifyPwdVo pVo){
        System.out.println("=============修改密码==============="+pVo);
        return ebcUserService.modifyPwd(pVo);

    }



}
